const { allExamineFlowList } = require('../../../../api/app')
const { dateFormat, inputchange, anit } = require('../../../../utils/util')

Page({
    data: {
        pickerDate: {
            start: '',
            end: '',
            today: '',
            show: false
        },
        searchText: '',
        examineList: []
    },
    static:{
        pageNum: 1,
        pageSize: 20,
        beginCreateTime: '',
        endCreateTime: '',
        searchText: '',
        hasNextPage: true
    },
    onReady(){
        this.setData({
            ['picker.today']:dateFormat('YYYY-mm-dd',new Date())
        })
        this.getExamine()
    },
    // onReachBottom(){
    //     this.getExamine()
    // },
    searchExamine(event){
        console.log(event)
        if(anit(event)){
            this.static.searchText = event.detail ? event.detail.value : this.static.searchText
            this.static.pageNum = 1
            this.static.hasNextPage = true
            this.data.examineList = []
            this.getExamine()
        }
    },
    getExamine(){
        if(!this.static.hasNextPage){
            return 
        }
        allExamineFlowList(this.static).then(res=>{
            this.data.examineList.push(...res.list)
            this.setData({
                examineList: this.data.examineList
            })
            this.static.pageNum += 1
            this.static.hasNextPage = res.hasNextPage
        })
    },
    inputChange(event){
        inputchange(event,this)
    },
    onSelectDate(){
        this.setData({
            ['pickerDate.show']: true,
        })
        wx.setNavigationBarColor({
            backgroundColor: '#FFFFFF',
            frontColor: '#000000',
            animation: {
                duration: 400,
                timingFunc: 'easeIn'
            }
        })
    },
    onSubmitDate(){
        this.static.beginCreateTime = this.data.pickerDate.start
        this.static.endCreateTime = this.data.pickerDate.end
        this.searchExamine({
            timeStamp: 0
        })
        this.setData({
            ['pickerDate.show']: false
        })
        wx.setNavigationBarColor({
            backgroundColor: '#fafafc',
            frontColor: '#000000',
            animation: {
                duration: 400,
                timingFunc: 'easeIn'
            }
        })
    },
    goExamine(event) {
        wx.navigateTo({
            url: '/packagePay/pages/examine/detail/detail?id=' + event.currentTarget.dataset.id
        })
    },
    onCancelDate(){
        this.setData({
            ['pickerDate.show']: false,
            ['pickerDate.start']: '',
            ['pickerDate.end']: ''
        })
        wx.setNavigationBarColor({
            backgroundColor: '#fafafc',
            frontColor: '#000000',
            animation: {
                duration: 400,
                timingFunc: 'easeIn'
            }
        })
    },
})